package com.aptemo.webetek.client.widgets.payments;

import java.util.MissingResourceException;

import com.aptemo.webetek.client.Webetek;
import com.aptemo.webetek.client.widgets.CurrencyWidget;
import com.aptemo.webetek.client.widgets.DateTimeWidget;
import com.aptemo.webetek.shared.PaymentBean;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class PaymentRow
		extends Composite
{

	private static PaymentRowUiBinder	uiBinder	= GWT.create(PaymentRowUiBinder.class);

	interface PaymentRowUiBinder extends UiBinder<Widget, PaymentRow>
	{
	}

	@UiField
	DateTimeWidget	dateField;

	@UiField
	Label			descriptionField;

	@UiField
	Label			typeField;

	@UiField
	CurrencyWidget	amountField;

	public PaymentRow(PaymentBean payment)
	{
		initWidget(uiBinder.createAndBindUi(this));

		dateField.setValue(payment.getDate());
		descriptionField.setText(payment.getDescription());
		if (payment.getType() != null)
		{
			typeField.setText(translate(payment.getType().toString()));
		}
		amountField.setValue(payment.getAmount());
	}

	public String translate(String key)
	{
		try
		{
			return Webetek.getConstants().getString(key);
		}
		catch (MissingResourceException e)
		{
			return key;
		}
	}

}
